/*
 * displayLists.c
 *
 *  Created on: 28/11/2008
 *      Author: root
 */
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>

#define PRIVADA 1
#define SABONETEIRA 2
#define PIA 3
#define RALO 4
#define LIXEIRA 5
#define PORTA_PAPEL 6
#define PAREDES 7
#define JANELA 8
#define LAMPADA 9
#define DESCARGA 10
#define TORNEIRA 11
#define SIFAO 12
#define MADEIRA 13
#define PORTA_BOX 14
#define CHAO 15
#define CEU 16

int Rotate=0,Scaling=0,Translate=0,Camera=0;
char objName[30];
char selected[30];
float specular[4] = {0.0, 0.0, 0.0, 1.0};
float emission[4] = {0.0, 0.0, 0.0, 1.0};
float emission2[4] = {0.0, 0.0, 0.0, 1.0};
float emissionR[4] = {0.0, 0.0, 0.0, 1.0};
double s[3] = {1, 1, 1};
double t[3] = {-1.200000, -3.200000, -105.000000};
double r[3] = {0, 0, 0};
double c[3] = {0, 0, 0};
int angle = 0;
float coef = 0.1;
float coefMorn = 2;
float   angulo = 0,                 //Variaveis
	theta = 0,                  //utilizadas
	xCamPos = 0,                //pra guardar a posição
	yCamPos = 0.5,              //da camera
	zCamPos = -70,                //e o ponto
	xCamFocus,              //para onde
	yCamFocus,            //estamos
	zCamFocus,              //observando
	rot_Porta = 1,
 	x_Porta = 0,
 	z_Porta = 0,
 	aberto = 1,
	rot_Porta2 = 1,
 	x_Porta2 = 0,
 	z_Porta2 = 0,
 	aberto2 = 1;

/*Funcao que pula as quatro primeiras linhas dos arquivos .obj*/
void skipInit(FILE *arq) {

	size_t size = 50;
	char *linha = malloc(size);
	int i;

	for(i=0; i<4; i++)
		getline(&linha, &size, arq);

}
/*Funcao que recebe um arquivo e as cores de um objeto*/
void createObject(char object[], double r, double g, double b) {

	FILE *arq;
	char currentCh;
	char useless[80];
	int numVertices = 0, numFaces = 0;
	//Abre o arquivo de pontos e faces de um objeto
	arq = fopen( object, "r");

	skipInit(arq);
	//Salva o número de faces e vértices de um objeto
	while ((currentCh = getc(arq)) != EOF){

	    if (currentCh == 'v') numVertices++;
	    if (currentCh == 'f') numFaces++;

	}
	/*Cria matrizes de vertices, faces e normais*/
	double vertices[numVertices][3];
	int faces[numFaces][3];
	double normals[numVertices][3];
	/*Retorna ao começo do arquivo*/
	rewind(arq);

	skipInit(arq);

	int i;
	/*Salva os vertices do objeto na matrix de vetices*/
	for(i=0; i<numVertices; i++)
		fscanf(arq, "%s %lf %lf %lf\n", useless, &vertices[i][0], &vertices[i][1],&vertices[i][2] );
	/*Salva os faces do objeto na matrix de faces*/
	for(i=0; i<numFaces; i++)
		fscanf(arq, "%s %d %d %d\n", useless, &faces[i][0], &faces[i][1],&faces[i][2] );
	/*Salva os normal dos vertices na matrix de normais*/
	for(i=0; i<numVertices; i++){
		double sum = 0;
		int j=0;

		for(j=0; j<3; j++) sum += vertices[i][j]*vertices[i][j];

		sum = sqrt(sum);
		if(sum > 0) for(j=0; j<3; j++) normals[i][j] = vertices[i][j]/sum;
	}

	glMatrixMode(GL_MODELVIEW);

	float k[] = {r, g, b, 1.0};
	float k2[] = {r-0.2, g-0.2, b-0.2, 1.0};

	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, k2);
	if(!strstr(object,"torneira-final.obj")) glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, k);
	//glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, k);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 40);
	/*Gera as faces com os vertices e suas normais*/
	for(i=0; i<numFaces; i++){
		glBegin(GL_TRIANGLES);
			glNormal3dv(normals[faces[i][0]-1]);
			glVertex3dv(vertices[faces[i][0]-1]);
			glNormal3dv(normals[faces[i][1]-1]);
			glVertex3dv(vertices[faces[i][1]-1]);
			glNormal3dv(normals[faces[i][2]-1]);
			glVertex3dv(vertices[faces[i][2]-1]);
		glEnd();
	}

    fclose(arq);

}


/*Funcao auto-explicativa*/
void createDisplayLists(){

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glNewList(PRIVADA, GL_COMPILE);
		createObject("Privada.obj", 0.9, 0.9, 0.9);
	glEndList();

	glNewList(SABONETEIRA, GL_COMPILE);
		createObject("Saboneteira.obj", 0.6, 0.6, 0.6);
	glEndList();

	glNewList(PIA, GL_COMPILE);
		createObject("pia.obj", 0.6, 0.6, 0.5);
	glEndList();

	glNewList(RALO, GL_COMPILE);
		createObject("ralo.obj", 0.9, 0.9, 0.9);
	glEndList();

	glNewList(LIXEIRA, GL_COMPILE);
		createObject("Lixeira.obj", 0.5, 0.3, 0.3);
	glEndList();

	glNewList(PORTA_PAPEL, GL_COMPILE);
		createObject("PortaPapel.obj", 0.9, 0.9, 0.9);
	glEndList();

	glNewList(PAREDES, GL_COMPILE);
		createObject("BanheiroEstrutura.obj", 0.95, 0.95, 0.95);
	glEndList();

	glNewList(JANELA, GL_COMPILE);
		createObject("janela.obj", 0.7, 0.7, 0.7);
	glEndList();

	glNewList(LAMPADA, GL_COMPILE);
		createObject("lampada.obj", 0.63, 0.63, 0.63);
		if(coef == 0.02) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, 0);
	glEndList();

	glNewList(DESCARGA, GL_COMPILE);
		createObject("Descarga.obj", 0.63, 0.63, 0.63);
	glEndList();

	glNewList(TORNEIRA, GL_COMPILE);
		specular[0] = 0.2;
		specular[1] = 0.2;
		specular[2] = 0.2;
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
		createObject("torneira-final.obj", 0.4, 0.4, 0.4);
		specular[0] = 0;
		specular[1] = 0;
		specular[2] = 0;
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
	glEndList();

	glNewList(SIFAO, GL_COMPILE);
		specular[0] = 0.1;
		specular[1] = 0.1;
		specular[2] = 0.1;
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
		createObject("sifao.obj", 0.45, 0.45, 0.45);
		specular[0] = 0;
		specular[1] = 0;
		specular[2] = 0;
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
	glEndList();

	glNewList(MADEIRA, GL_COMPILE);
		createObject("porta_esc.obj", 0.274510, 0.117647, 0.078431);
	glEndList();

	glNewList(PORTA_BOX, GL_COMPILE);
	createObject("porta.obj", 0.596078,0.043137, 0.043137);
	glEndList();

	glNewList(CHAO, GL_COMPILE);
		createObject("plane.obj", 0.905882, 0.701961, 0.474510);
	glEndList();

	glNewList(CEU, GL_COMPILE);
		createObject("plane.obj", 0.635294, 0.827451, 0.925490);
	glEndList();

}
/*Funcao que monitora o tecaldo recebe como argumentos uma tecla e a posição do mouse*/
void key( unsigned char k, int x, int y ){

	if( k == 'r') if(Rotate == 0) {Camera=0;Rotate = 1; Scaling = 0; Translate = 0;}       //Se a tecla for r entramos no modo de rotacionar
	if( k == 's') if(Scaling == 0) {Camera=0;Scaling = 1; Rotate = 0; Translate = 0;}      //Se a tecla for s entramos no modo de escalonar
	if( k == 't') if(Translate == 0) {Camera=0;Translate = 1; Scaling = 0; Rotate = 0;}    //Se a tecla for t entramos no modo de tranladar
	if( k == 'c') if(Camera == 0) {Camera=1;Translate = 0; Scaling = 0; Rotate = 0;}
	if(k == 'd'){
		if(Rotate == 1) {
			angle += 2;
			r[0] = 0;
			r[1] = 0;
			r[2] = 1;
			glutPostRedisplay();
		}
		if(Translate == 1){
			t[2] += 0.2;
			glutPostRedisplay();
		}
		if(Camera == 1){
			c[2] += 1;
			glutPostRedisplay();
		}
	}
	if(k == 'a'){
		if(Rotate == 1) {
			angle -= 2;
			r[0] = 0;
			r[1] = 0;
			r[2] = 1;
			glutPostRedisplay();
		}
		if(Translate == 1){
			t[2] -= 0.2;
			glutPostRedisplay();
		}
		if(Camera == 1){
			c[2] -= 1;
			glutPostRedisplay();
		}
	}
	if(k == 'q'){exit(0);}  //Se a tecla for q saimos do programa


	if(k=='l'){

		coef = 0.2;
		emission[0] = 0;
		emission[1] = 0;
		emission[2] = 0;
		glutPostRedisplay();
	}
 	if(k=='k'){

		coef = 0.07;
		emission[0] = 0.4;
		emission[1] = 0.4;
		emission[2] = 0.4;
		glutPostRedisplay();
	}

	if(k=='m'){

		coefMorn = 2;
		glutPostRedisplay();
	}
 	if(k=='n'){

		coefMorn = 30;
		glutPostRedisplay();
	}

	

	/*Botoes da camera*/

	/*A tecla 'u' faz com que a camera "olhe" para cima*/
	if (k == 'u'){
		theta -= (1.5*3.1415)/180;
		xCamFocus = xCamPos - 2*cos(theta)*sin(angulo);
		zCamFocus = zCamPos - 2*cos(theta)*cos(angulo);
		yCamFocus = yCamPos - 2*sin(theta);
		glutPostRedisplay();
	}

	/*A tecla 'd' faz com que a camera "olhe" para baixo*/
	if(k == 'j'){
		theta += (1.5*3.1415)/180;
		xCamFocus = xCamPos - 2*cos(theta)*sin(angulo);
		zCamFocus = zCamPos - 2*cos(theta)*cos(angulo);
		yCamFocus = yCamPos - 2*sin(theta);
		glutPostRedisplay();
	}

	/*A tecla '5' faz com que a camera se mova na direção em que esta olhando(mover-se para frente)*/
	if (k == '5'){
		xCamPos -= 1*cos(theta)*sin(angulo);
		zCamPos -= 1*cos(theta)*cos(angulo);
		xCamFocus = xCamPos - 2*cos(theta)*sin(angulo);
		zCamFocus = zCamPos - 2*cos(theta)*cos(angulo);
		glutPostRedisplay();
	}

	/*A tecla '2' faz com que a camera se mova na direção contraria a que esta olhando(mover-se para tras)*/
	if (k == '2'){
		xCamPos += 1*cos(theta)*sin(angulo);
		zCamPos += 1*cos(theta)*cos(angulo);
		xCamFocus = xCamPos - 2*cos(theta)*sin(angulo);
		zCamFocus = zCamPos - 2*cos(theta)*cos(angulo);
		glutPostRedisplay();
	}

	/*A tecla '1' faz com que a camera aumente sua altura em relacao ao chao(Mover-se para cima)*/
	if (k == '1'){
		yCamPos += 0.2;
		xCamFocus = xCamPos - 2*cos(theta)*sin(angulo);
		zCamFocus = zCamPos - 2*cos(theta)*cos(angulo);
		yCamFocus = yCamPos - 2*sin(theta);
		glutPostRedisplay();
	}

	/*A tecla '3' faz com que a camera diminua sua altura em relacao ao chao(Mover-se para baixo)*/
	if (k=='3'){
		yCamPos -= 0.2;
		xCamFocus = xCamPos - 2*cos(theta)*sin(angulo);
		zCamFocus = zCamPos - 2*cos(theta)*cos(angulo);
		yCamFocus = yCamPos - 2*sin(theta);
		glutPostRedisplay();
	}

	/*A tecla '4' faz com que a camera "olhe" para a esquerda*/
	if (k=='4'){
		angulo += (1.5*3.1415)/180;
		xCamFocus = xCamPos - 2*cos(theta)*sin(angulo);
		zCamFocus = zCamPos - 2*cos(theta)*cos(angulo);
		yCamFocus = yCamPos - 2*sin(theta);
		glutPostRedisplay();
	}

	/*A tecla '6' faz com que a camera "olhe" para a direita*/
	if (k=='6'){
		angulo -= (1.5*3.1415)/180;
		xCamFocus = xCamPos - 2*cos(theta)*sin(angulo);
		zCamFocus = zCamPos - 2*cos(theta)*cos(angulo);
		yCamFocus = yCamPos - 2*sin(theta);
		glutPostRedisplay();
	}

	//Rotaciona a porta
	if(k=='x'){
		if (aberto == 1){
			rot_Porta = 10;
			x_Porta = 6;
			z_Porta = 1.5;
			aberto = 0;
		}
		else {
			rot_Porta = 1;
			x_Porta = 0;
			z_Porta = 0;
			aberto = 1;		
		}
		glutPostRedisplay();
	}
	
	//Rotaciona a outra porta
	if(k=='z'){
		if (aberto2 == 1){
			rot_Porta2 = -40;
			x_Porta2 = 2;
			z_Porta2 = -4;
			aberto2 = 0;
		}
		else {
			rot_Porta2 = 1;
			x_Porta2 = 0;
			z_Porta2 = 0;
			aberto2 = 1;		
		}
		glutPostRedisplay();
	}

	//printf("%lf \n", pos[1]);

}
/*Funcao que monitora o teclado recebe como entrada uma tecla especial e a posicao corrente do mouse*/
void specialKey(int k, int x, int y){

	if(k == GLUT_KEY_F1) {Rotate = 0; Scaling = 0; Translate = 0;} //Se a tecla for F1 saimos do modo de rotate, sacaling e translate
	if(k == GLUT_KEY_UP){
		if(Rotate == 1) {
			angle += 2;
			r[0] = 1;
			r[1] = 0;
			r[2] = 0;
			glutPostRedisplay();
		}
		if(Scaling == 1){
			s[0] += 0.1;
			s[1] += 0.1;
			s[2] += 0.1;
			glutPostRedisplay();
		}
		if(Translate == 1){
			t[1] += 0.2;
			glutPostRedisplay();
		}
		if(Camera == 1){
			c[1] += 1;
			glutPostRedisplay();
		}

	}
	if(k == GLUT_KEY_DOWN){
		if(Rotate == 1) {
			angle -= 2;
			r[0] = 1;
			r[1] = 0;
			r[2] = 0;
			glutPostRedisplay();
		}
		if(Scaling == 1){
			s[0] -= 0.1;
			s[1] -= 0.1;
			s[2] -= 0.1;
			glutPostRedisplay();
		}
		if(Translate == 1){
			t[1] -= 0.2;
			glutPostRedisplay();
		}
		if(Camera == 1){
			c[1] -= 1;
			glutPostRedisplay();
		}

	}
	if(k == GLUT_KEY_RIGHT){
		if(Rotate == 1) {
			angle += 2;
			r[0] = 0;
			r[1] = 1;
			r[2] = 0;
			glutPostRedisplay();
		}
		if(Translate == 1){
			t[0] += 0.2;
			glutPostRedisplay();
		}
		if(Camera == 1){
			c[0] += 1;
			glutPostRedisplay();
		}

	}
	if(k == GLUT_KEY_LEFT){
		if(Rotate == 1) {
			angle -= 2;
			r[0] = 0;
			r[1] = 1;
			r[2] = 0;
			glutPostRedisplay();
		}
		if(Translate == 1){
			t[0] -= 0.2;
			glutPostRedisplay();
		}
		if(Camera == 1){
			c[0] -= 1;
			glutPostRedisplay();
		}
	}


}

/*Funcao que inicializa os valores para a execucao do programa*/
void myInit(){

	glClearColor(0.31372549,0.780392157,0.847058824, 1);
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	gluPerspective( 60, 1, 0.1, 150.0 );
	glMatrixMode( GL_MODELVIEW );
	createDisplayLists();

}
/*Funcao que renderiza os objetos na tela*/
void display(){

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glClear( GL_COLOR_BUFFER_BIT );

	glEnable(GL_DEPTH_TEST);
	xCamFocus = xCamPos - 2*cos(theta)*sin(angulo);
	zCamFocus = zCamPos - 2*cos(theta)*cos(angulo);
	yCamFocus = yCamPos - 2*sin(theta);
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
	glClear( GL_DEPTH_BUFFER_BIT );

	glShadeModel(GL_SMOOTH);

	glEnable(GL_DEPTH_TEST);

//HABILITANDO AS LUZES

	GLfloat light_pos0[] = {-2.400000, 11.600000, -138.600000, 1.0};
	GLfloat light_pos1[] = {6.000000, -5.600000, -45.000000, 1.0};
	GLfloat diffuse[] = {2, 2, 2, 1.0};
	GLfloat ambient[] = {0.9, 0.9, 0.9, 1.0};
	GLfloat specular[] = {0.7, 0.7, 0.7, 1.0};

	glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);

	glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, coefMorn);

	glLightfv(GL_LIGHT0, GL_POSITION, light_pos0);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
	glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
	glLightfv(GL_LIGHT0, GL_SPECULAR, specular);

	glLightf(GL_LIGHT1, GL_LINEAR_ATTENUATION, coef);

	glLightfv(GL_LIGHT1, GL_POSITION, light_pos1);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
	glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
	glLightfv(GL_LIGHT1, GL_SPECULAR, specular);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHT1);

	glLoadIdentity();

//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//PAREDES
	glTranslatef(-5.400000, -0.400000, -79.200000);
	glRotatef(0, 0.000000, 0.000000, 0.000000);
	glScalef(8.4, 8.4, 8.4);
	glCallList(PAREDES);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//PRIVADA 01
	glTranslatef(-0.200000, -6.400000, -114.200000);
	glRotatef(0, 0, 0, 0);
	glScalef(2.300000, 2.300000, 2.300000);
	glCallList(PRIVADA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//PRIVADA 02
	glTranslatef(-9.800000, -6.400000, -114.200000);
	glRotatef(0, 0, 0, 0);
	glScalef(2.300000, 2.300000, 2.300000);
	glCallList(PRIVADA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//LAMPADA
	glTranslatef(-5.400000, 9.000000, -92.200000);
	glRotatef(0, 0, 0, 0);
	glScalef(1.800000, 1.800000, 1.800000);
	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission);
	glCallList(LAMPADA);
	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emissionR);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//PIA 01
        glTranslatef(-12.000000, -5.600000, -84.000000);
	glRotatef(-268, 0.000000, 1.000000, 0.000000);
	glScalef(0.700000, 0.700000, 0.700000);
	glCallList(PIA);

        glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//PIA 02
	glTranslatef(-12.000000, -5.600000, -90.800000);
	glRotatef(-268, 0.000000, 1.000000, 0.000000);
	glScalef(0.700000, 0.700000, 0.700000);
	glCallList(PIA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//TORNEIRA 01
	glTranslatef(-11.400000, -2.800000, -84.200000);
	glRotatef(-26, 0, 1, 0);
	glScalef(0.300000, 0.300000, 0.300000);
	glCallList(TORNEIRA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//TORNEIRA 02
	glTranslatef(-11.400000, -2.800000, -91.400000);
	glRotatef(-26, 0, 1, 0);
	glScalef(0.3, 0.3, 0.3);
	glCallList(TORNEIRA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//SIFAO 01
	glTranslatef(-12.400000, -4.800000, -83.600000);
	glRotatef(-272, 0, 1, 0);
	glScalef(0.5, 0.5, 0.5);
	glCallList(SIFAO);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//SIFAO 02
	glTranslatef(-12.400000, -5.000000, -90.600000);
	glRotatef(-272, 0, 1, 0);
	glScalef(0.5, 0.5, 0.5);
	glCallList(SIFAO);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//JANELA
	glTranslatef(-2.400000, 9.000000, -121.800000);
	glRotatef(-90, 0, 1, 0);
	glScalef(2.100000, 2.100000, 2.100000);
	glCallList(JANELA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//RALO 01
	glTranslatef(-2.800000, -9.600000, -116.800000);
	glRotatef(0, 0, 0, 0);
	glScalef(0.8, 0.8, 0.8);
	glCallList(RALO);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//RALO 02
	glTranslatef(-12.600000, -9.600000, -116.800000);
	glRotatef(0, 0, 0, 0);
	glScalef(0.8, 0.8, 0.8);
	glCallList(RALO);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//RALO 03
	glTranslatef(-11.800000, -9.600000, -88.000000);
	glRotatef(0, 0, 0, 0);
	glScalef(0.8, 0.8, 0.8);
	glCallList(RALO);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//LIXEIRA 01
	glTranslatef(-1.800000, -8.400000, -116.800000);
	glRotatef(0, 0, 0, 0);
	glScalef(1, 1, 1);
	glCallList(LIXEIRA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//LIXEIRA 02
	glTranslatef(3.400000, -8.400000, -116.800000);
	glRotatef(0, 0, 0, 0);
	glScalef(1, 1, 1);
	glCallList(LIXEIRA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//DESCARGA 01
	glTranslatef(-0.000000, -2.200000, -118.000000);
	glRotatef(-92, 0, 1, 0);
	glScalef(0.2, 0.2, 0.2);
	glCallList(DESCARGA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//DESCARGA 02
	glTranslatef(-9.800000, -2.200000, -118.000000);
	glRotatef(-92, 0, 1, 0);
	glScalef(0.2, 0.2, 0.2);
	glCallList(DESCARGA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//PORTA PAPEL 01
	glTranslatef(-11.600000, -5.200000, -118.200000);
	glRotatef(0, 0, 0, 0);
	glScalef(0.8, 0.8, 0.8);
	glCallList(PORTA_PAPEL);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//PORTA PAPEL 02
	glTranslatef(-2.600000, -5.400000, -118.200000);
	glRotatef(0, 0, 0, 0);
	glScalef(0.8, 0.8, 0.8);
	glCallList(PORTA_PAPEL);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//FORRAMENTO 01
	glTranslatef(-0.600000, -7.000000, -107.200000);
	glRotatef(-458, 0, 1, 0);
	glScalef(5.700000, 5.700000, 5.700000);
	glCallList(MADEIRA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//FORRAMENTO 02
	glTranslatef(1.200000, -6.800000, -107.600000);
	glRotatef(-94, 0, 1, 0);
	glScalef(5.6, 5.6, 5.6);
	glCallList(MADEIRA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//PORTA BOX
	glTranslatef(-1.200000+x_Porta, -3.200000, -105.00000+z_Porta);
	glRotatef(10*rot_Porta, 0, 1, 0);
	glScalef(3.800000, 3.800000, 3.800000);
	glCallList(PORTA_BOX);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//PORTA BOX
	glTranslatef(-17.200000+x_Porta2, -3.200000, -106.000000+z_Porta2);
	glRotatef(2*rot_Porta2, 0, 1, 0);
	glScalef(3.800000, 3.800000, 3.800000);
	glCallList(PORTA_BOX);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//SABONETEIRA
	glTranslatef(-13.000000, -0.800000, -87.200000);
	glRotatef(0,0,0,0);
	glScalef(0.6, 0.6, 0.6);
	glCallList(SABONETEIRA);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//CHAO
	glTranslatef(44.800000, -18.600000, -69.600000);
	glRotatef(0.000000, 0.000000, 0.000000, 0);
	glScalef(8.4, 8.4, 8.4);
	glCallList(CHAO);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
//CEU
	glTranslatef(59.000000, -2.800000, -118.400000);
	glRotatef(-58, 1.000000, 0.000000, 0.000000);
	glScalef(10.600000, 10.600000, 10.600000);

	if(coefMorn == 2) {emission2[0] = 0;
	emission2[1] = 0.327451;
	emission2[2] = 0.325490;}
	else{
	emission2[0] = 0;
	emission2[1] = 0;
	emission2[2] = 0;}

	glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION,emission2);
	glCallList(CEU);
	emission2[0] = 0;
	emission2[1] = 0;
	emission2[2] = 0;
	glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION, emission2);

	glLoadIdentity();
//camera();
	gluLookAt(xCamPos, yCamPos, zCamPos, xCamFocus, yCamFocus, zCamFocus, 0.0, 1.0, 0.0);
	glutSwapBuffers();

	/*glTranslatef(t[0], t[1], t[2]);
	glRotatef(angle, r[0]. r[1], r[2]);
	glScalef(s[0], s[1], s[2]);*/

}
//FUNCAO PRINCIPAL
int main( int argc, char **argv  ){

	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize( 700, 700 );
	glutInitWindowPosition( 0,0 );
	glutCreateWindow("\"Banheiro\"");
	glutKeyboardFunc(key);
	glutSpecialFunc(specialKey);
	myInit();
	glutDisplayFunc(display);
	glutMainLoop();

	return(0);
}



